//
//  CellForRecommedImage.m
//  MY Project For Sport
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForRecommedImage.h"
#import "ModelForRecommend.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <DKNightVersion.h>
#import "UIColor+Wonderful.h"
#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface CellForRecommedImage ()

@property (nonatomic, retain) UILabel *labelForTitle;
@property (nonatomic, retain) UIImageView *firstImageview;
@property (nonatomic, retain) UIImageView *secondImageview;
@property (nonatomic, retain) UIImageView *thirdImageview;
@property (nonatomic, retain) UIView *view;


@end


@implementation CellForRecommedImage
-(void)dealloc {
    
    [_labelForTitle release];
    [_firstImageview release];
    [_secondImageview release];
    [_thirdImageview release];
    [_view release];
    [super dealloc];

}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithColors([UIColor linenColor], [UIColor grayColor]);

        [self createSubview];
    }
    

    return self;
    
}
- (void)createSubview {

    self.view = [[UIView alloc] init];
    [self.contentView addSubview:self.view];
    [_view release];

    
    self.labelForTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTitle];
    [_labelForTitle release];
    
    self.firstImageview = [[UIImageView alloc] init];
    [self.contentView addSubview:self.firstImageview];
    [_firstImageview release];
    
    self.secondImageview = [[UIImageView alloc] init];
    [self.contentView addSubview:self.secondImageview];
    [_secondImageview release];
    
    self.thirdImageview = [[UIImageView alloc] init];
    [self.contentView addSubview:self.thirdImageview];
    [_thirdImageview release];
    
}

- (void)layoutSubviews {

    [super layoutSubviews];
    
    self.view.frame = CGRectMake(2, 5, self.contentView.frame.size.width - 4, self.contentView.frame.size.height - 10);
    //self.view.backgroundColor = [UIColor whiteColor];
    self.view.dk_backgroundColorPicker = DKColorWithRGB (0xffffff, 0x343434);
    
    self.labelForTitle.frame = CGRectMake(5 * WEIGHTT, 5 * HEIGHTT, self.contentView.frame.size.width / 3 * 2, self.contentView.frame.size.height / 6);
    self.labelForTitle.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
   // self.labelForTitle.backgroundColor = [UIColor orangeColor];
    
    self.firstImageview.frame = CGRectMake(2 * WEIGHTT, 10 * HEIGHTT + self.contentView.frame.size.height / 5, (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, self.contentView.frame.size.height - self.contentView.frame.size.height / 5 - 16 * HEIGHTT);
   // self.firstImageview.backgroundColor = [UIColor redColor];
    
    self.secondImageview.frame = CGRectMake(15 * WEIGHTT + (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, 10 * HEIGHTT+ self.contentView.frame.size.height / 5, (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, self.contentView.frame.size.height  - self.contentView.frame.size.height / 5 - 16 * HEIGHTT);
    //self.secondImageview.backgroundColor = [UIColor yellowColor];
    
    self.thirdImageview.frame = CGRectMake(25 * WEIGHTT + (self.contentView.frame.size.width - 30 * WEIGHTT) / 3 + (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, 10 * HEIGHTT + self.contentView.frame.size.height / 5,(self.contentView.frame.size.width - 26 * WEIGHTT) / 3, self.contentView.frame.size.height  - self.contentView.frame.size.height / 5 - 16 * HEIGHTT);
    //self.thirdImageview.backgroundColor = [UIColor blueColor];

 
}

- (void)passModelForRecommedImage:(ModelForRecommend *)model {

    self.labelForTitle.text = model.stitle;

    [self.firstImageview sd_setImageWithURL:[NSURL URLWithString:[[model.images objectAtIndex:0] objectForKey:@"u"]]];
    
    if (model.images.count < 2) {
        
        [self.secondImageview sd_setImageWithURL:[NSURL URLWithString:[[model.images objectAtIndex:0] objectForKey:@"u"]]];

        [self.thirdImageview sd_setImageWithURL:[NSURL URLWithString:[[model.images objectAtIndex:0] objectForKey:@"u"]]];

        
    }else {
    
    
        [self.secondImageview sd_setImageWithURL:[NSURL URLWithString:[[model.images objectAtIndex:1] objectForKey:@"u"]]];
        
    
    }
    
    if (model.images.count < 3 ) {
       [self.thirdImageview sd_setImageWithURL:[NSURL URLWithString:[[model.images objectAtIndex:0] objectForKey:@"u"]]];
        
    }else {
 [self.thirdImageview sd_setImageWithURL:[NSURL URLWithString:[[model.images objectAtIndex:2] objectForKey:@"u"]]];
    }
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
